﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using EFMysql;
using CustomMVC;


namespace ShuaDanMysql.Controllers
{
    public class BaseController : Controller
    {      

        public BaseController() { }

        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);
            List<Tuple<pre_user, string, int, List<pre_privileges>>> loginUser = WebVar<Tuple<pre_user, string, int, List<pre_privileges>>>.GetList;
            List<Tuple<pre_user, string, int, List<pre_privileges>>> user = loginUser.FindAll(o => o.Item2.ToString() == requestContext.HttpContext.Session.SessionID);
            if (user.Count < 1)
            {
                requestContext.HttpContext.Response.Redirect("~");
            }
        }

        protected virtual List<pre_privileges> GetFuncPrivilege(string sessionId)
        {
            List<Tuple<pre_user, string, int, List<pre_privileges>>> userList = WebVar<Tuple<pre_user, string, int, List<pre_privileges>>>.GetList;
            Tuple<pre_user, string, int, List<pre_privileges>> user = userList.Find(o => o.Item2 == sessionId);
            return user.Item4;
        }
    }
}
